package com.macro.mall.tiny.modules.pms.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.macro.mall.tiny.common.api.CommonResult;
import com.macro.mall.tiny.modules.pms.model.PmsActivationCode;
import com.macro.mall.tiny.modules.pms.model.PmsActivationCodeUse;
import com.macro.mall.tiny.modules.pms.service.PmsActivationCodeUseService;
import io.swagger.annotations.ApiOperation;
import io.swagger.v3.oas.annotations.Operation;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.parameters.P;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 激活码使用记录表 前端控制器
 * </p>
 *
 * @author tyrone
 * @since 2025-03-02
 */
@RestController
@RequestMapping("/pms/pmsActivationCodeUse")
public class PmsActivationCodeUseController {
    @Autowired
    private PmsActivationCodeUseService pmsActivationCodeUseService;

    @ApiOperation("万能后题分页查询")
    @PostMapping("/page")
    public CommonResult<Page<PmsActivationCodeUse>> page(@RequestBody PmsActivationCodeUse pmsActivationCodeUse) {
        Page<PmsActivationCodeUse> page = new Page<>(pmsActivationCodeUse.getPageNum(), pmsActivationCodeUse.getPageSize());
        QueryWrapper<PmsActivationCodeUse> wrapper = new QueryWrapper<>();
        if (pmsActivationCodeUse.getActivationTimeStart() != null) {
            wrapper.ge("activation_time", pmsActivationCodeUse.getActivationTimeStart());
        }
        if (pmsActivationCodeUse.getActivationTimeEnd() != null) {
            wrapper.le("activation_time", pmsActivationCodeUse.getActivationTimeEnd());
        }
        if (pmsActivationCodeUse.getCreateTimeStart() != null) {
            wrapper.ge("create_time", pmsActivationCodeUse.getCreateTimeStart());
        }
        if (pmsActivationCodeUse.getCreateTimeEnd() != null) {
            wrapper.le("create_time", pmsActivationCodeUse.getCreateTimeEnd());
        }
        if (StringUtils.isNotEmpty(pmsActivationCodeUse.getCode())) {
            wrapper.like("code", pmsActivationCodeUse.getCode());
        }
        if (pmsActivationCodeUse.getMemberId() != null) {
            wrapper.eq("member_id", pmsActivationCodeUse.getMemberId());
        }
        if (pmsActivationCodeUse.getId() != null) {
            wrapper.eq("id", pmsActivationCodeUse.getId());
        }

        return CommonResult.success(pmsActivationCodeUseService.page(page, new QueryWrapper<>(pmsActivationCodeUse)));
    }
}

